//
// Created by thomas on 9/9/21.
//

#ifndef DCSMINI_FILECOPY_H
#define DCSMINI_FILECOPY_H

#include <QThread>
#include <QStringList>
#include <utility>

#define FILE_BLOCKSIZE      (4 * 1024)
#define FILE_WATER_LEVEL    (5 * 1024 * 1024)

enum
{
    OPERATE_START = 0,
    OPERATE_STOP,
    OPERATE_FILE_NAME,
    OPERATE_COPY_TOTAL_RATE,
    OPERATE_COPY_SINGLE_RATE,
    OPERATE_DELETE_TOTAL_RATE,
    OPERATE_ERROR_MEM_FULL
} COPY_STATION;

enum
{
    SUCCESS = 0,
    ERROR_SRC_PATH_NULL,
    ERROR_DES_PATH_NULL,
    ERROR_NO_FILES,
    ERROR_MEM_FULL
} RETURN_VALUE;

typedef enum FILE_ACTION
{
    FILE_ACTION_NONE = 0,
    FILE_ACTION_COPY,       //文件拷贝
    FILE_ACTION_DEL,        //文件删除
} FILE_ACTION_EN;

class FileManageThread : public QThread
{
Q_OBJECT
public:
    FileManageThread();

    void run() override;

    int operateStart(enum FILE_ACTION action);

    void operateStop();

    void setSrcDirPath(QString path)
    {
        mSrcPath = std::move(path);
    }

    void setDesDirPath(QString path)
    {
        mDesPath = std::move(path);
    }

private:
    QStringList mFileList;      //文件链表
    QString mSrcPath;
    QString mDesPath;
    bool mbStop{};
    quint64 mFileTotalSize{0};
    quint64 mCurSize{0};
    enum FILE_ACTION mAction{FILE_ACTION_NONE};

    int fileCopy(const QString &fileName);

    static int fileDelete(const QString &fileName);

signals:

    void operateStationSig(int flag, QString qsText);
};

#endif //DCSMINI_FILECOPY_H
